<% include header %>
    <div class="container">
        <form class="form create" method="post">
            <div>
                <label>用户名:</label>
                <input class="input" placeholder="用户名" type="text" name="name">
            </div>
            <div>
                <label>密码:</label>
                <input class="input" placeholder="密码" type="password" name="password">
            </div>
            <div>
                <label>重复密码:</label>
                <input class="input" placeholder="重复密码" type="password" name="repeatpass">
            </div>
            <div class="submit">注册</div>
        </form>
    </div>
    <script type="text/javascript">
        $('.submit').click(() => {
            console.log($('.form').serialize());
            $.ajax({
                url: '/signup',
                data: $('.form').serialize(),
                type: 'post',
                dataType: 'json',
                cache: false,
                success: function(msg) {
                    if (msg.data == 1) {
                        $('.error').text('用户名存在');
                        $('input').val('');
                        fade('.error');
                    } else if (msg.data == 2) {
                        $('.error').text('重复密码输入不一致');
                        fade('.error');
                    } else if (msg.data == 3) {
                        $('.success').text('注册成功');
                        fade('.success');
                        setTimeout(() => {
                            window.location.href = '/signin';
                        }, 1000);
                    }
                },
                error: function() {
                    alert('注册出现异常');
                }
            })
        })
    </script>
    <% include footer %>